import axios from 'axios'
import { Message } from 'element-ui'

const baseUrl=process.env.API_HOST
console.log(baseUrl)

const instance=axios.create({
     baseURL:baseUrl,
     timeout:100000,
})

instance.interceptors.request.use(config=>{
    const token = localStorage.getItem("token")
    if(token){
      config.headers.token=token
    }
    return config
},
    error=>{
  Message({
    message:'请求错误',
    type:'error'
  })
})

instance.interceptors.response.use(response=>{
  console.log(response)
  if(response.status===200){
      if(response.data.status===200){
        return response.data
      }else{
        return Promise.reject(response.data)
      }
  }
},error=>{
   let errMsg=''
  if(error.response){
    switch (error.response.status) {
      case 400:
      errMsg="请求错误"
      break
    }
  }


})


export default instance
